
using System;
using System.Collections;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
namespace NCS_CS
{
	//Imports 
	public partial class FrmStandard
	{
		public bool mconfirm;
		SortableBindingList2<NCS.standard> o;// = new SortableBindingList<Word>();;
        public void getData()
        {
            IList l = ModMain.getsession().CreateCriteria(typeof(NCS.standard)).List();
            o = new SortableBindingList2<NCS.standard>();;
			
            foreach (NCS.standard s in l)
            {
                o.Add(s);
            }
			this.DataGrid1.DataSource = o;

        }
		private void FrmStandard_Load(object sender, System.EventArgs e)
		{
			//'Dim o As Object
			//'o = session.CreateSQLQuery("select * from standard order by cconc").AddEntity(GetType(NCS.standard)).List()
            getData();
			if (o.Count < 1)
				return;
			DataGrid1.Columns["cconc"].HeaderText = "O%";
			DataGrid1.Columns["sconc"].HeaderText = "N%";
			DataGrid1.Columns["description"].Visible = false;
			DataGrid1.Columns["ID"].Visible = false;
			DataGrid1.Columns["userid"].Visible = false;
			DataGrid1.Columns["name"].HeaderText = "名称";
		}

		private void Button2_Click(System.Object sender, System.EventArgs e)
		{
			this.mconfirm = true;
			if (ModMain.getsession().IsDirty()) {
				ModMain.getsession().Flush();
			}
			this.Visible = false;
		}

		private void Button3_Click(System.Object sender, System.EventArgs e)
		{
			Button3.Enabled = false;
			object id = null;
			id = this.DataGrid1.CurrentRow.DataBoundItem;
			ModMain.getsession().Delete(id);
			ModMain.getsession().Flush();
			//o.Remove(id)
            //o = ModMain.getsession().CreateCriteria(typeof(NCS.standard)).List();
            //this.DataGrid1.DataSource = o;
            getData();
			Button3.Enabled = true;
		}

		private void Button1_Click(System.Object sender, System.EventArgs e)
		{
			Button1.Enabled = false;
			NCS.standard m = new NCS.standard();
			m.name = this.TextBox1.Text;
			m.cconc = Convert.ToSingle(this.TextBox2.Text);
			m.sconc = Convert.ToSingle(this.TextBox3.Text);
			ModMain.getsession().Save(m);
			ModMain.getsession().Flush();
            //o = ModMain.getsession().CreateCriteria(typeof(NCS.standard)).List();
            //this.DataGrid1.DataSource = o;
            getData();
			Button1.Enabled = true;
		}
		public FrmStandard()
		{
			Load += FrmStandard_Load;
			InitializeComponent();
		}

	}
}
